home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 for Intel / NeXTSTEP 3.2 for Intel.iso / NextCD / CDIS / MiniSystem.gnutar.z / MiniSystem.gnutar / private / etc / rc.boot < prev    next >
Encoding:
Text File  |  1993-08-24  |  4.4 KB  |  158 lines

  1. #!/bin/sh -u
  2. #
  3. # This script sets up the machine enough to run single-user
  4. #
  5. # Copyright (C) 1993 by NeXT Computer, Inc.  All rights reserved.
  6. #
  7. # Note that all "echo" commands are in parentheses so that
  8. # the main shell does not open a tty and get its process group set.
  9.  
  10. #
  11. # Initialize the path to be used and inherited by all the commands herein
  12. #
  13. if [ -f /.path ]; then
  14.     . /.path
  15. else
  16.     PATH=/usr/ucb:/bin:/usr/bin:/etc:/usr/etc; export PATH
  17.     HOME=/; export HOME
  18. fi
  19.  
  20. iscdrom=0
  21.  
  22. (echo)                                 > /dev/console
  23.  
  24. # Start with some -- any! -- reasonable hostname
  25. hostname localhost
  26.  
  27. # Are we booting from a CD-ROM?  If so, make a note of the fact.
  28.  
  29. if [ -d /NextCD ]; then
  30.   (echo "Root device is a CD-ROM.  Filesystem checks skipped.") > /dev/console
  31.   iscdrom=1
  32. fi
  33.  
  34. swapfile=/private/vm/swapfile
  35. swapdir=/private/vm
  36.  
  37. # We must fsck here before we touch anything in the filesystems.
  38. fsckerror=0
  39.  
  40. # Output the date for reference.
  41. date                                >/dev/console
  42.  
  43. # Don't fsck if we're single-user, or if we're on a CD-ROM.
  44.  
  45. if [ $1x = singleuserx -a $iscdrom -ne 1 ]; then
  46.     (echo "Singleuser boot -- fsck not done")        >/dev/console
  47.     # Ensure that the root filesystem is mounted read-write.
  48.     mount -o remount /                    >/dev/console
  49.     # Is there a swapfile?  Print a warning if not.
  50.     if [ ! -f $swapfile ]; then
  51.         (echo "No default swapfile present!")        >/dev/console
  52.     fi
  53. elif [ $iscdrom -ne 1 ]; then
  54.     # We're neither single-user nor on a CD-ROM.
  55.     # Erase the rom's old-style login panel
  56.     fbshow -B -E
  57.     fbshow -B -I "Checking disk" -z 5
  58.     (echo Checking disks)                    >/dev/console
  59.     # Benignly clean up ("preen") any dirty filesystems. 
  60.     # fsck -p will skip disks which were properly unmounted during
  61.     # a normal shutdown.
  62.     fsck -p                         >/dev/console 2>&1
  63.     # fsck's success is reflected in its status.
  64.     case $? in
  65.         0)
  66.             # No problems
  67.         ;;
  68.         2) 
  69.             # Request was made (via SIGQUIT, ^\) to complete fsck
  70.         # but prevent going multi-user.
  71.         (echo "Request to remain single-user received.") > /dev/console
  72.         fsckerror=1
  73.         ;;
  74.         
  75.         4)
  76.         # The root filesystem was checked and fixed.  Let's reboot.
  77.         # Note that we do NOT sync the disks before rebooting, to
  78.         # ensure that the filesystem versions of everything fsck fixed
  79.         # are preserved, rather than being overwritten when in-memory
  80.         # buffers are flushed.
  81.         (echo "Root fixed - rebooting.")        >/dev/console
  82.         reboot -q -n
  83.         ;;
  84.         8)
  85.         # Serious problem was found.
  86.         (echo "Reboot failed...help!")            >/dev/console
  87.         fsckerror=1
  88.         ;;
  89.         12)
  90.         # fsck was interrupted by SIGINT (^C)
  91.         (echo "Reboot interrupted.")            >/dev/console
  92.         fsckerror=1
  93.         ;;
  94.         *)
  95.         # Some other error condition ocurred.
  96.         (echo "Unknown error in reboot fsck.")        >/dev/console
  97.         fsckerror=1
  98.         ;;
  99.     esac
  100.     # Ensure root filesystem is mounted read-write.
  101.     mount -o remount /                    >/dev/console
  102.     # Make sure the swapfile exists
  103.     if [ ! -f $swapfile ]; then
  104.         (echo -n "Creating default swapfile")        >/dev/console
  105.         mkdirs -o root -g wheel -m 755 $swapdir
  106.         touch $swapfile
  107.         # Swapfile needs to have the "sticky" bit set.
  108.         chmod 1600 $swapfile
  109.         (echo " - rebooting")                >/dev/console
  110.         reboot -q
  111.     fi
  112. fi
  113.  
  114. # Read in configuration information.
  115. . /etc/hostconfig
  116.  
  117. # Fake mount entries for root and private filesystems (i.e., ensure that
  118. # they appear in /etc/mtab; filesystems mounted by the kernel aren't yet
  119. # recorded in mtab).
  120.  
  121. if [ $iscdrom -ne 1 ]; then
  122.     (echo "Faking root mount entries")            >/dev/console
  123.     # Clean out /etc/mtab.
  124.     > /etc/mtab
  125.     mount -f /
  126.     mount -f /private
  127. fi
  128.  
  129. sync
  130.  
  131. # If booted into single-user mode from a CD-ROM, print out some hints 
  132. # about how to fake up /tmp and get to other disks.
  133.  
  134. if [ $1x = singleuserx -a $iscdrom -eq 1 ]; then
  135.     (( 
  136.         echo ""
  137.     echo "You are now in single-user mode while booted from a CD-ROM."
  138.     echo "Since the root disk is read-only, some commands may not work as"
  139.     echo "they normally do.  In particular, commands that try to create"
  140.     echo "files in /tmp will probably fail.  One way to avoid this problem"
  141.     echo "is to mount a separate hard disk or floppy on /tmp using the"
  142.     echo "mount command.  For example,'/etc/mount -n /dev/fd0a /tmp' puts"
  143.     echo "/tmp on the internal floppy disk. (The -n option prevents mount"
  144.     echo "from trying to record the mount in /etc/mtab.)"
  145.     echo ""
  146.     ) > /dev/console )
  147. fi
  148.  
  149. # Exit with error if failed above.  ifconfig exits 1 if the error is 
  150. # a showstopper and 2 if it is not.  The only non-showstopper is the network
  151. # being down.
  152.  
  153. if [ $fsckerror -ne 0 ]; then
  154.     exit 1
  155. fi
  156.  
  157. exit 0
  158.